package com.atguigu.srb.core.controller.api;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.hfb.RequestHelper;
import com.atguigu.srb.core.pojo.vo.UserBindVo;
import com.atguigu.srb.core.service.UserBindService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户绑定表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/api/core/userBind")
public class ApiUserBindController {
    @Autowired
    UserBindService userBindService;
    ///api/core/userBind/notify
    @ApiOperation("hfb账户绑定后的回调接口")
    @PostMapping("notify") // success代表处理成功    fail代表处理失败
    public String nofity(HttpServletRequest request){
        try {
            userBindService.bindNotify(request);
            return "success";
        } catch (Exception e) {
            return "fail";//有异常返回失败
        }
    }


    @ApiOperation("账户绑定")
    @PostMapping("auth/bind") // 以后路径中包含auth的接口必须登录后才可以访问
    public R accountBind(@RequestHeader("token")String token,
                         @RequestBody UserBindVo userBindVo){//表单数据：自定义vo类   token
        String formStr = userBindService.accountBind(token, userBindVo);
        return R.success().data("formStr",formStr);
    }

}

